package www.lagou.dao;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import www.lagou.entity.Phone;
import www.lagou.utils.DruidUtils;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class PhoneDao {

    /**
     * 需求1:  查询价格高于2000元，生产日期是2019年之前的所有手机
     * @param price
     * @param prodate
     * @return
     * @throws SQLException
     */
    public List<Phone> queryPhone1(Double price,String prodate) throws SQLException {
        QueryRunner qr=new QueryRunner(DruidUtils.getDataSource());
        String sql="select *from phone where price>? and prodate<? ";
        List<Phone> list = qr.query(sql, new BeanListHandler<Phone>(Phone.class), price,prodate);
        return list;

    }
    /**
     * 需求2:  查询所有颜色是白色的手机信息
     */
    public List<Phone> queryPhone2(String color) throws SQLException {
        QueryRunner qr=new QueryRunner(DruidUtils.getDataSource());
        String sql="select *from phone where color=? ";
        List<Phone> list =qr.query(sql,new BeanListHandler<Phone>(Phone.class),color);
        return list;
    }
}
